<!-- 注册页面 -->
<template>
  <div class="login-container">
    <el-form
      ref="registForm"
      :model="registForm"
      class="login-form"
      auto-complete="on"
      label-position="left"
    >
      <h3 class="title">资产管理系统</h3>
      <el-form-item prop="username">
        <span class="svg-container">
          <svg-icon icon-class="user"/>
        </span>
        <el-input
          v-model="registForm.accountName"
          name="username"
          type="text"
          auto-complete="on"
          placeholder="注测账户"
        />
      </el-form-item>
      <el-form-item prop="password">
        <span class="svg-container">
          <svg-icon icon-class="password"/>
        </span>
        <el-input
          :type="pwdType"
          v-model="registForm.password"
          name="password"
          auto-complete="on"
          placeholder="password"
          @keyup.enter.native="handleSave"
        />
        <span class="show-pwd" @click="showPwd">
          <svg-icon :icon-class="pwdType === 'password' ? 'eye' : 'eye-open'"/>
        </span>
      </el-form-item>

<!-- 公司名称 -->
      <el-form-item prop="name">
        <span class="svg-container">
          <svg-icon icon-class="user"/>
        </span>
        <el-input
          v-model="registForm.name"
          name="companyname"
          type="text"
          auto-complete="on"
          placeholder="companyname"
        />
      </el-form-item>

<!-- 行业类型 -->
      <el-form-item prop="type">
        <span class="svg-container">
          <svg-icon icon-class="user"/>
        </span>
        <el-select
          v-model="registForm.type" id="select"
          placeholder="行业类型"
        >
          <el-option label="计算机" value="0"></el-option>
          <el-option label="互联网" value="1"></el-option>
          <el-option label="物联网" value="2"></el-option>
          <el-option label="其他"   value="3"></el-option>
        </el-select>
      </el-form-item>

<!-- 人员规模 -->
      <el-form-item prop="scale">
        <span class="svg-container">
          <svg-icon icon-class="user"/>
        </span>
        <el-select
          v-model="registForm.scale" id="select"
          placeholder="人员规模"
        >
          <el-option label="20人以下" value="0"></el-option>
          <el-option label="20-50人"  value="1"></el-option>
          <el-option label="50-100人" value="2"></el-option>
          <el-option label="其他"     value="3"></el-option>
        </el-select>
      </el-form-item>   

      <el-form-item>
        <el-button
          :loading="loading"
          type="primary"
          style="width:100%;"
          @click.native.prevent="handleSave"
        >注册</el-button>
      </el-form-item>
      <!-- <div class="tips">
        <span style="margin-right:20px;">username: admin</span>
        <span>password: admin</span>
      </div>-->
    </el-form>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
// import { regist } from "@/api/login";
import { save } from "@/api/login";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    //这里存放数据
    return {
      registForm: {
        accountName: "",
        password: "",
        name: "",
        type: "",
        scale: "",
      },
      pwdType: "password",
      loading: false
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    showPwd() {
      if (this.pwdType === "password") {
        this.pwdType = "";
      } else {
        this.pwdType = "password";
      }
    },
    // handleLogin() {
    //   regist(this.registForm).then(res => {});
    // },

    handleSave() {
      save(this.registForm).then(res => {
        this.$router.go(-1)
      });
    },



  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {} //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;
.login-container {
  position: fixed;
  height: 100%;
  width: 100%;
  background-color: $bg;
  .login-form {
    position: absolute;
    left: 0;
    right: 0;
    width: 520px;
    max-width: 100%;
    padding: 35px 35px 15px 35px;
    margin: 120px auto;
  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;
    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }
  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }
  .title {
    font-size: 26px;
    font-weight: 400;
    color: $light_gray;
    margin: 0px auto 40px auto;
    text-align: center;
    font-weight: bold;
  }
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
</style>
